<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>课程包管理</title>
<style type="text/css">
input[type=radio], input[type=checkbox] {
	width: 20px;
	height: 20px;
}
</style>

<%@ include file="../common/importLib.jsp"%>
<script type="text/javascript" src="/mrjy/common/jquery-easyui/js/jquery.jdirk.js"></script>
<script type="text/javascript" src="/mrjy/common/jquery-easyui/js/jeasyui.extensions.combobox.autoComplete.js"></script>
<script type="text/javascript">
	var videoFileSize = 0;

	/**
	 * 增删改查参数设置
	 */
	tableTitle = "课程包视频管理";
	tableURL = getTimeURL("coursePackageVideoRel/selectPage.do");
	toolbarView = 7;
	tableColumns = [ [
			{
				field : 'ck',
				checkbox : true
			},
			{
				field : 'id',
				title : 'id',
				width : 0,
				rowspan : 1
			},
			{
				field : 'opt',
				title : '操作',
				width : 120,
				align : 'center',
				rowspan : 1,
				formatter : function(value, rowData, rowIndex) {
					var queryUrl = 'coursePackageVideoRel/selectById.do?id=' + rowData.id;
					var html = "<a title='修改' class='xxl_linkbutton' iconCls='icon-edit' href='javascript:datagridUpdate(\""
							+ queryUrl
							+ "\")'>修改</a>";
					return html;
				}
			},
			{
				field : 'coursePackageName',
				title : '课程包名称',
				width : 200,
				align : 'center',
				rowspan : 1
			}, {
				field : 'videoName',
				title : '视频名称',
				width : 200,
				align : 'center',
				rowspan : 1
			}, {
				field : 'videoDesc',
				title : '视频描述',
				width : 200,
				align : 'center',
				rowspan : 1
			}, {
				field : 'userName',
				title : '主讲人',
				width : 60,
				rowspan : 1
			}, {
				field : 'coursePackageType',
				title : '课程包类型',
				width : 120,
				rowspan : 1,
				formatter : function(value, rowData, rowIndex) {
					if (rowData.coursePackageType == 1) {
						return "<font color='green'>主题课程包</font>";
					} else if(rowData.coursePackageType == 2) {
						return "<font color='green'>导师课程包</font>";
					}
				}
			}, {
				field : 'createTimeString',
				title : '创建时间',
				width : 150,
				rowspan : 1
			}, {
				field : 'sort',
				title : '排序',
				width : 60,
				rowspan : 1
			}] ];

	var addWidth = 830; //添加窗口宽度
	var addHeight = 520; //添加窗口高度
	var addTitle = "添加课程包视频"; //添加标题
	var updateWidth = 830; //修改窗口宽度
	var updateHeight = 520; //修改窗口高度
	var updateTitle = "修改课程包视频"; //修改标题
	var deleteUri = "coursePackageVideoRel/deleteByIds.do"; //删除记录

	/**
	 * 初始化添加表单
	 */
	function initAddForm() {
		
	}

	/**
	 * 初始化修改表单
	 */
	function initUpdateForm(jsonObject) {
		var info = jsonObject.info
		$("#idUpdate").val(info.id);
		$("#coursePackageNameUpdate").html(info.coursePackageName);
		$("#videoNameUpdate").html(info.videoName);
		$("#sortUpdate").val(info.sort);
		
	}

	function submitForm() {
		
		var params = getFormJson($('#update_form'));
		$.ajax({
			  type: 'POST',
			  url: '../coursepackage/coursePackageVideoRel/updateById.do',
			  data: params,
			  dataType: 'json',
			  async: false,
			  success: function(data){
				  if(data.err_code ==0){
					  $('#datagrid_update').window('close');
					  $('#datagrid_table').datagrid('reload');
				  }
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
		});
	}

	function cancelForm() {
		$('#datagrid_update').window('close');
	}

	/**
	 *删除记录之后执行函数
	 */
	function afterDelete() {
		
	}

	function clearForm() {
		
	}

	function addFormSubmit() {
		/* var params = getFormJson($('#add_form'));
		$.ajax({
			  type: 'POST',
			  url: '../coursepackage/coursePackageInfo/insert.do',
			  data: params,
			  dataType: 'json',
			  async: false,
			  success: function(data){
				  if(data.err_code ==0){
					  $('#datagrid_add').window('close');
					  $('#datagrid_table').datagrid('reload');
				  }
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
		});
			 */
	}
	
	
	//将form中的值转换为键值对。
	function getFormJson(frm) {
	    var o = {};
	    var a = $(frm).serializeArray();
	    $.each(a, function () {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });

	    return o;
	}
</script>
<script type="text/javascript">
	$(function() {
		$("#userIdQuery").combobox({
			url : "../maintain/userInfo/userListNoPage.do?roleId=2",
			valueField : 'id',
			textField : 'text',
			editable : true,
			onSelect : function(data) {
			}
		});
	});
</script>

</head>
<body id="layout" class="easyui-layout">
	<div
		style="background: none repeat scroll 0% 0% #EFEFEF; height: 68px; padding: 6px 2px; border-bottom: 1px solid #CCC;"
		region="north" split="false" title="条件查询">
		<form id="searchForm">
			<table>
				<tr>
					<td width="20px"></td>
					<td>导师：</td>
					<td>
						<input type="text" id="userIdQuery" name="userId" style="width: 120px" />
					</td>
					<td width="20px"></td>
					<td>课程包名称：</td>
					<td>
						<input type="text" id="coursePackageNameQuery" name="coursePackageName" style="width: 120px" />
					</td>
					<td width="20px"></td>
					<td>
						<a class="easyui-linkbutton" id="search" iconCLs="icon-search" onclick="searchTable()">搜索</a>
					</td>
					<td>
						<a class="easyui-linkbutton" iconCls="icon-undo" onclick="document.getElementById('searchForm').reset();clearForm();reload();">清空</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div region="center" style="font-family: 微软雅黑">
		<!-- datagrid信息表 -->
		<table id="datagrid_table"></table>
	</div>
	<!-- 添加记录 -->
	<div id="datagrid_add">
		<form id="add_form" action="coursePackageInfo/insert.do" method="POST">
			<table border="0" width="770" class="xxl_tb_1"
				style="font-size: 13px">
				<tbody>
					
					<tr>
						<td colspan="3" style="text-align: center"><a
							class="easyui-linkbutton" iconCls="icon-ok"
							onclick="addFormSubmit()">添加</a> <a class="easyui-linkbutton"
							iconCls="icon-undo"
							onclick="document.getElementById('add_form').reset()">重置</a> <a
							class="easyui-linkbutton" iconCls="icon-cancel"
							onclick="$('#datagrid_add').window('close');">取消</a></td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>

	<!-- 修改记录 -->
	<div id="datagrid_update">
		<form id="update_form" action="coursePackageVideoRel/updateById.do" method="post">
			<input type="hidden" id="idUpdate" name="id" />
			<table border="0" width="770" class="xxl_tb_1">
				<tbody>
					<tr>
						<td class="xxl_td_2">课程包名称：</td>
						<td >
							<div id="coursePackageNameUpdate"></div>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2">视频名称：</td>
						<td >
							<div id="videoNameUpdate"></div>
						</td>
					</tr>
					<tr>
						<td class="xxl_td_2">课程排序：</td>
						<td >
							<input type="text" id="sortUpdate" name="sort" class="easyui-numberbox" />
						</td>
					</tr>
					<tr>
						<td colspan="3" style="text-align: center"><a
							class="easyui-linkbutton" iconCls="icon-ok"
							onclick="submitForm()">修改</a> <a class="easyui-linkbutton"
							iconCls="icon-cancel" onclick="cancelForm()">取消</a></td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>

</body>
</html>